package com.flysh.host.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.flysh.host.model.Menu;
import com.flysh.host.service.MenuManagerService;
import com.flysh.host.service.SystemAccessManagerService;
import com.flysh.host.service.SystemAccessManagerServiceImpl;
import com.flysh.host.util.JSONUtil;

public class MenuServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		   request.setCharacterEncoding("utf-8");
		   response.setCharacterEncoding("utf-8");
		   response.setContentType("text/html;charset=utf-8");
		   
		   String  menuId = request.getParameter("menuId")==null?"0":request.getParameter("menuId");
		 
		   Map<Long,List<Menu>> rootMap = (Map<Long,List<Menu>>)request.getSession().getAttribute("rootMap");
		   List<Menu> list = rootMap.get(Long.parseLong(menuId));
		   for (Menu menu : list) {
			System.out.println(menu.getId()+","+menu.getMenuName());
		   }
		   String json = JSONUtil.getMenuJSON(list);
		   PrintWriter out = response.getWriter();
		   out.write(json);
		   out.close();
		   
         
	
	}
	
	

}
